<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="王佳佳">
    <title>只是轮播的轮播图</title>
    <style>
        *
        {
            box-sizing: border-box;
        }
        body
        {
            margin: 0;
        }
        main
        {
            position: relative;
            width: 490px;
            height: 300px;
            margin: 50px auto;
        }
        main img
        {
            width: 100%;
            height: 100%;
            display: none;
        }
        main img.current
        {
            display: block;
        }

        main section
        {
            position: absolute;
            /* border: 1px solid black; */
            width: 100px;
            height: 20px;
            line-height: 20px;
            display: flex;
            justify-content: space-between;
            margin-left: 195px;
            margin-top: -30px;
        }
        main div
        {
            border-radius: 50%;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            background-color: white;
        }
        main div.button
        {
            background-color: skyblue;
        }
    </style>
</head>
<body>
    <script src="./jquery.js"></script>
    <main>
        <img class="current" src="./img/01.jpg" alt="">
        <img src="./img/02.jpg" alt="">
        <img src="./img/03.jpg" alt="">
        <img src="./img/04.jpg" alt="">
        <img src="./img/05.jpg" alt="">
        <section>
            <div class="button">1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
        </section>
    </main>

</body>
</html>

<script>
    var index = 0;
    var timer = setInterval(showimg,1500);
    function showimg()
    {
        index++;
        if(index == 5)
        {
            index = 0;
        }
        $('img').eq(index).addClass('current').siblings().removeClass('current');
        $('div').eq(index).addClass('button').siblings().removeClass('button');
    };

    $('div').each(function()
    {
        $(this).hover(
            function()
            {
                clearInterval(timer);
                $(this).addClass('button').siblings().removeClass('button');
                console.log($(this).index());
                $('img').eq($(this).index()).addClass('current').siblings().removeClass('current');
            },
            function()
            {
                timer = setInterval(showimg,1500);
                index = $(this).index();
            }
        )
    });
</script>